package cn.wolfcode.luowowo.member.domain;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
@Setter
public class PersonInfo implements Serializable {
    private Long userId; //用户id

    private String attentionUserId;//关注的ids:String类型

    private List<Long> attentionUserIds;//关注的ids:List<Long>类型

    private int attentionNum;//关注总数

    private String fansId;//粉丝的ids:String类型

    private List<Long> fansIds;//粉丝的ids:List<Long>类型

    private int fansNum;//粉丝总数

    private Integer MEL;//蜂蜜(积分)

    private String address;//地址

    private int visitNum;//访客总数

    private int dayNum;//日总数

    //添加编辑时，前端传入是long数组， 数据库保存的是id拼接的字符串
    public String getFansId(){
        //id1,id2,id3
        return StringUtils.join(fansIds, ",");
    }

    //从数据库拿出的id拼接字符串转换成数组
    public List<Long> getFansIds(){
        if(StringUtils.isNotBlank(fansId)){
            Long[] ids = new Long[]{};
            String[] strs = fansId.split(",");
            ids = new Long[strs.length];
            for (int i = 0; i <strs.length ; i++) {
                ids[i] =  Long.parseLong(strs[i]);
            }
            return Arrays.asList(ids);
        }
        return new ArrayList<Long>();
    }

    //粉丝总数
    public int getFansNum(){
        if(StringUtils.isNotBlank(attentionUserId)){
            return getAttentionUserIds().size();
        }
        return 0;
    }

    //添加编辑时，前端传入是long数组， 数据库保存的是id拼接的字符串
    public String getAttentionUserId(){
        //id1,id2,id3
        return StringUtils.join(attentionUserIds, ",");
    }

    //从数据库拿出的id拼接字符串转换成数组
    public List<Long> getAttentionUserIds(){
        if(StringUtils.isNotBlank(attentionUserId)){
            Long[] ids = new Long[]{};
            String[] strs = attentionUserId.split(",");
            ids = new Long[strs.length];
            for (int i = 0; i <strs.length ; i++) {
                ids[i] =  Long.parseLong(strs[i]);
            }
            return Arrays.asList(ids);
        }
        return new ArrayList<Long>();
    }

    //关注总数
    public int getAttentionNum(){
        if(StringUtils.isNotBlank(attentionUserId)){
            return getAttentionUserIds().size();
        }
        return 0;
    }

}